package com.person.controller;

import com.person.common.R;
import com.person.pojo.Orders;
import com.person.pojo.PageBean;
import com.person.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;
@Slf4j
@RequestMapping("/order")
@RestController
public class OrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 后台分页查询订单
     */
    @GetMapping("/page")
    public R<PageBean> getOrderList(@RequestParam(defaultValue = "1") Integer page,
                                  @RequestParam(defaultValue = "10") Integer pageSize,
                                  String number, LocalDateTime beginTime,LocalDateTime endTime){
        PageBean orderList = orderService.getBackendPage(page,pageSize,beginTime,endTime,number);
        return R.success(orderList);
    }
    /**
     * 后台派送
     */
    @PutMapping
    public R<String> orderDelivery(@RequestBody Orders orders) {
        int result = orderService.orderDelivery(orders);

        return result > 0 ?  R.success("修改成功") :  R.error("操作失败");
    }

    /**
     * 提交订单
     * @param orders
     * @return
     */
    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
        orderService.submit(orders);
        return R.success("提交成功");
    }

    /**
     * 查看订单
     */
    @GetMapping("/userPage")
    public PageBean showOrders(Integer page, Integer pageSize){
        log.info("查看订单：{}",page,pageSize);

        PageBean pageBean = orderService.getPage(page, pageSize);
        return pageBean;
    }


}
